// Package models /*
package models

import (
	"time"

	"gorm.io/gorm"
	"gostudy/pkg/mysqlx"
	"gostudy/pkg/utils/strings"
)

type AdminUsers struct {
	mysqlx.BaseModle
	id        uint   `gorm:"primary_key;auto_increment"`
	Username  string `gorm:"size:100;comment:'用户名'"`
	Nickname  string `gorm:"size:100;comment:'姓名'"`
	Password  string `gorm:"size:200;comment:'密码'"`
	LastLogin string `gorm:"size:30;comment:'最后登录ip地址'"`
	Salt      string `gorm:"size:32;comment:'密码盐'"`
	Header    string `gorm:"size:20;comment:'头部皮肤'"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AdminUserIndexReq struct {
	Nickname  string `form:"nickname"`
	CreatedAt string `form:"create_time"`
	UpdatedAt string `form:"create_time"`
}

type AdminUserSaveReq struct {
	Username string `form:"username" label:"用户名" binding:"required"`
	Password string `form:"password"`
	Nickname string `form:"nickname" label:"姓名" binding:"required"`
}

type AdminUserEditPassReq struct {
	Uid         int    `form:"id"`
	OldPassword string `form:"old_password" label:"原始密码" binding:"required"`
	NewPassword string `form:"new_password" label:"新密码" binding:"required"`
	SubPassword string `form:"sub_password" label:"确认密码" binding:"required"`
}

//type AdminUserSkinReq struct {
//	Type  string `form:"type" json:"type"`
//	Color string `form:"color" json:"color"`
//	Uid   int
//}

func (au *AdminUsers) TableName() string {
	return "pay_admin"
}

func (au *AdminUsers) FillData(db *gorm.DB) {
	//初始化管理员
	salt := strings.RandString(6)
	passwordSalt := strings.Encryption("111111", salt)
	adminUser := AdminUsers{
		Username:  "admin",
		Nickname:  "管理员",
		Password:  passwordSalt,
		LastLogin: "",
		Salt:      salt,
		Header:    "default",
	}
	db.Save(&adminUser)
}

func (au *AdminUsers) GetConnName() string {
	return "default"
}
